package com.ruoyi.washer.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.washer.domain.XwPurchaseOrder;
import com.ruoyi.washer.service.IXwPurchaseOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 购买记录Controller
 * 
 * @author hawking
 * @date 2023-12-15
 */
@RestController
@RequestMapping("/washer/order")
public class XwPurchaseOrderController extends BaseController
{
    @Autowired
    private IXwPurchaseOrderService xwPurchaseOrderService;

    /**
     * 查询购买记录列表
     */
    @PreAuthorize("@ss.hasPermi('washer:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(XwPurchaseOrder xwPurchaseOrder)
    {
        startPage();
        List<XwPurchaseOrder> list = xwPurchaseOrderService.selectXwPurchaseOrderList(xwPurchaseOrder);
        return getDataTable(list);
    }

    /**
     * 导出购买记录列表
     */
    @PreAuthorize("@ss.hasPermi('washer:order:export')")
    @Log(title = "购买记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, XwPurchaseOrder xwPurchaseOrder)
    {
        List<XwPurchaseOrder> list = xwPurchaseOrderService.selectXwPurchaseOrderList(xwPurchaseOrder);
        ExcelUtil<XwPurchaseOrder> util = new ExcelUtil<XwPurchaseOrder>(XwPurchaseOrder.class);
        util.exportExcel(response, list, "购买记录数据");
    }

    /**
     * 获取购买记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('washer:order:query')")
    @GetMapping(value = "/{orderNo}")
    public AjaxResult getInfo(@PathVariable("orderNo") Long orderNo)
    {
        return success(xwPurchaseOrderService.selectXwPurchaseOrderByOrderNo(orderNo));
    }

    /**
     * 新增购买记录
     */
    @PreAuthorize("@ss.hasPermi('washer:order:add')")
    @Log(title = "购买记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody XwPurchaseOrder xwPurchaseOrder)
    {
        return toAjax(xwPurchaseOrderService.insertXwPurchaseOrder(xwPurchaseOrder));
    }

    /**
     * 修改购买记录
     */
    @PreAuthorize("@ss.hasPermi('washer:order:edit')")
    @Log(title = "购买记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody XwPurchaseOrder xwPurchaseOrder)
    {
        return toAjax(xwPurchaseOrderService.updateXwPurchaseOrder(xwPurchaseOrder));
    }

    /**
     * 删除购买记录
     */
    @PreAuthorize("@ss.hasPermi('washer:order:remove')")
    @Log(title = "购买记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderNos}")
    public AjaxResult remove(@PathVariable Long[] orderNos)
    {
        return toAjax(xwPurchaseOrderService.deleteXwPurchaseOrderByOrderNos(orderNos));
    }
}
